package org.smr.ministore.micro.client;

import java.util.List;

import org.blade.utils.Pager;
import org.smr.ministore.entities.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import feign.hystrix.FallbackFactory;

@Component
public class HystrixEmployeeClientFactory implements FallbackFactory<FeignEmployeeMicroServiceClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixEmployeeClientFactory.class);

    @Override
    public FeignEmployeeMicroServiceClient create(Throwable cause) {
        HystrixEmployeeClientFactory.LOGGER.info("fallback; reason was: {}", cause.getMessage());

        return new EmployeeFeignClientWithFactory() {

            @Override
            public Employee queryById( Long id ) {
                Employee entity = new Employee();
                entity.setId(-1L);
                return entity;
            }

            @Override
            public int batchSave( List< Employee> entities){
                return 0;
            }



            public int save(Employee entity){
                return 0;
            }

            public int updateById(Employee id){
                return 0;
            }

            public int deleteById(Long id){
                 return 0;
            }

            public Pager<Employee> paginate( Employee entity, Long pageSize, Long pageNum){
                Pager<Employee> pager = new Pager<Employee>();
                return pager;
            }

        };//Return end
    }
}